<script setup>
import { getImageBanner } from "@/api/home.js";
import { ref, onMounted } from "vue";

const bannerList = ref([]);
const getBanner = async () => {
  const res = await getImageBanner();
  bannerList.value = res.data;
};
onMounted(() => {
  getBanner();
});
</script>

<template>
<div class="home-banner">
  <el-carousel :interval="4000" type="card" height="500px" arrow="always">
    <el-carousel-item v-for="item in bannerList" :key="item.id">
      <div class="image-wrapper">
        <img :src="item" alt="banner" />
      </div>
    </el-carousel-item>
  </el-carousel>
</div>
</template>

<style scoped>
.home-banner {
  width: 100%;
  height: 380px;
  position: relative; /* 改为相对定位，避免脱离文档流 */
  z-index: 98;
  margin: 20px auto; /* 水平居中 */
  overflow: hidden;
  border-radius: 20px;
}

/* 图片容器用于居中对齐 */
.image-wrapper {
  width: 100%;
  height: 100%;
  display: flex;
  align-items: center; /* 垂直居中 */
  justify-content: center; /* 水平居中 */
}

/* 图片美化 */
.image-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  border-radius: 20px;
  transition: transform 0.3s ease-in-out;
}

/* 图片悬停放大 */
.image-wrapper img:hover {
  transform: scale(1.05);
}

/* 轮播箭头美化 */
.el-carousel__arrow {
  background-color: rgba(0, 0, 0, 0.5);
  border-radius: 50%;
  transition: background-color 0.3s ease-in-out;
}

.el-carousel__arrow:hover {
  background-color: rgba(0, 0, 0, 0.8);
}
</style>